<%@ page contentType="text/html;charset=UTF-8" %>

<%
//monta o controlador de acordo com pessoa que está na session.
String controlador;
def estagiarioInstance = Estagiario.findById(session.pessoa.id);
if(estagiarioInstance != null){
    controlador = "estagiario";
}
def ucInstance = UnidadeConcedente.findById(session.pessoa.id);
if(ucInstance != null){
    controlador = "unidadeConcedente";
}
def ieInstance = InstituicaoEnsino.findById(session.pessoa.id);
if(ieInstance != null){
    controlador = "instituicaoEnsino";
}
%>
<h1 class="cabelistlateral">Responsáveis</h1>
<g:hasErrors bean="${responsavelInstance}">
<div class="errors">
    <g:renderErrors bean="${responsavelInstance}" as="list" />
</div>
</g:hasErrors>
<%
if(responsavelInstance?.id){
    %>
    <form method="post" action="${createLink(controller:'responsavel', action:'update', id:responsavelInstance.id)}">
    <%
}else{
    %>
    <form method="post" action="${createLink(controller:'responsavel', action:'save')}">
    <%
}
%>
    <g:hiddenField name="colaborador.id" value="${session.pessoa.id}" />
    <g:hiddenField name="tipo" value="${controlador}" />
    <div class="dialog">
        <table>
            <tbody>

                <tr class="prop cadastrolateral">
                    <td valign="top" colspan="3" class="name" class="value ${hasErrors(bean: responsavelInstance, field: 'nome', 'errors')}">
                        <label for="nome"><g:message code="responsavel.nome.label" default="Nome" /></label>
                        <br/>
                        <g:textField name="nome" maxlength="60" size="58" value="${responsavelInstance?.nome}" />
                    </td>
                    
                </tr>

                <tr class="prop cadastrolateral">
                    <td valign="top" class="name" class="value ${hasErrors(bean: responsavelInstance, field: 'cpf', 'errors')}">
                        <label for="cpf" class="name"><g:message code="responsavel.cpf.label" default="CPF" /></label>
                        <br/>
                        <g:textField name="cpf" maxlength="11" value="${responsavelInstance?.cpf}" />
                    </td>
                    <td valign="top" class="name" class="value ${hasErrors(bean: responsavelInstance, field: 'cargo', 'errors')}">
                        <label for="cargo"><g:message code="responsavel.cargo.label" default="Cargo" /></label>
                        <br/>
                        <g:textField name="cargo" maxlength="60" value="${responsavelInstance?.cargo}" />
                    </td>
                    <td class="btsalvarlateral">
                        <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
                    </td>
                </tr>

            </tbody>
        </table>
    </div>
</form>
<%
if(responsavelInstanceList){
    %>
    <div class="list">
      <table>
          <thead>
              <tr>
                  <g:sortableColumn property="nome" title="${message(code: 'responsavel.nome.label', default: 'Nome')}" />
                  <g:sortableColumn property="cargo" title="${message(code: 'responsavel.cargo.label', default: 'Cargo')}" />
                  <td colspan="2" class="acao">Ações</td>
              </tr>
          </thead>
          <tbody>
          <g:each in="${responsavelInstanceList}" status="i" var="responsavelInstance">
              <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                  <td>${fieldValue(bean: responsavelInstance, field: "nome")}</td>
                  <td>${fieldValue(bean: responsavelInstance, field: "cargo")}</td>
                  <td class="ico">
                    <a href="${createLink(controller:'responsavel', action:'edit', id:responsavelInstance.id, params:[tipo:controlador])}">
                      <img src="${resource(dir:'images',file:'ico_edit.png')}" alt="Editar Item" title="Editar Item" />
                    </a>
                  </td>
                  <td class="ico">
                      <a href="${createLink(controller:'responsavel', action:'delete', id:responsavelInstance.id, params:[tipo:controlador])}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Confirma aexclusão do registro?')}');">
                          <img src="${resource(dir:'images',file:'ico_delete.png')}" alt="Excluir Item" title="Excluir Item" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}"  />
                      </a>
                  </td>
              </tr>
          </g:each>
          </tbody>
      </table>
    </div>
    <div class="paginateButtons">
      <g:paginate total="${responsavelInstanceTotal}" />
    </div>
    <%
}
%>